<?php
/**
 * 商品
 */
class GoodsController extends CommonController{
	private $goods_model;
	private $cid;
	private $category;
	public function __auto(){
		$this->goods_model = K('goods');
		$this->cid = Q('cid',0,'intval');
		$this->category = Data::tree(M('category')->all(),'catname');
	}
	
	/**
	 * 显示商品
	 */
	public function index(){
		$goods = $this->goods_model->all();
		$this->assign('goods',$goods);
		$this->display();
	}
	/**
	 * 添加商品
	 */
	public function add(){
		if(IS_POST){
			if($this->goods_model->addGoods()){
				$this->success('添加商品成功！','index');
			}else{
				$this->error($this->goods_model->error);
			}
		}else{
			$this->assign('category',$this->category);
			$this->display();
		}
	}
	/**
	 * 修改商品
	 */
	public function edit(){
		$this->display();
	}
	/**
	 * 删除商品
	 */
	public function del(){
		
	}
	
	/**
	 * ajax请商品的属性值,并组合好表单（商品的筛选条件）
	 */
	public function getAttrForm(){
		$form = K('GoodsForm');
		$fied = $form->get();
		$this->assign('fied',$fied);
		$this->display();exit;
	}
	
	
}
